let count = 0
/**
 *
 * 搜索插入位置： https://leetcode-cn.com/problems/search-insert-position/
 *第二种思路：找到第一个大于等于target的数的下标
 *
 * @param {number[]} nums
 * @param {number} target
 * @return {number}
 */
var searchInsert = function (nums, target) {
  let l = 0
  let r = nums.length - 1
  let rslt = nums.length
  while (l <= r) {
    m = Math.floor(l + (r - l) / 2)
    if (nums[m] >= target) {
      // 遍历至l === r,此时rslt 为第一个大于等于target的数的下标
      r = m - 1
    } else {
      l = m + 1
    }
  }
  return rslt
}

console.log(searchInsert([1, 3, 5, 6], 7))
console.log('count', count)
//================v2要点总结===============
/**
 * 1.凝练最终的需求：找到第一个大于等于target的数的下标
 */
